package Servlet.camera;

import Dao.UserDao;
import Manage.Camera;
import Manage.User_login;
import Utils.mybatisUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.ibatis.session.SqlSession;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

public class jsoncameraServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter pw=response.getWriter();
        SqlSession session= mybatisUtils.getSqlSession();
        UserDao dao= session.getMapper(UserDao.class);
        List<User_login> list=new ArrayList<>();
        list=dao.selectallusername();
        String json=null;
        if (list.size()!=0){
            ObjectMapper om=new ObjectMapper();
            json=om.writeValueAsString(list);
        }
        pw.print(json);
        pw.flush();
        pw.close();
    }
}
